package com.deanlib.cabinet.data.network.intercept;

import com.deanlib.cabinet.utils.UserManager;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * Created by Dean on 2022/12/24
 */
public class AuthInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        okhttp3.Request request = chain.request();
        okhttp3.Request.Builder requestBuilder = request.newBuilder();
        if (UserManager.getInstance().isLogin()) {
            requestBuilder.addHeader("token", UserManager.getInstance().getToken())
                    .addHeader("uid", String.valueOf(UserManager.getInstance().getLogin().auth.userId));
        }
        return chain.proceed(requestBuilder.build());
    }
}
